package com.wh.wisdomsite.xbox.server.dbCompare;

import java.sql.*;

/**
 * Created by jinshaowei on 14/8/29.
 */
public class DBConnection {



    public static Connection getConn(String ip, String userName){

        String url = "jdbc:oracle:thin:@"+ ip +":1521:HAF";

        String username = userName;
        String password = "passw0rd";
        Connection connection = null;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return connection;

    }


    public static void close(PreparedStatement ps){

        // 关闭声明
        if (ps != null) {
            try {
                ps.close();
                } catch (SQLException e) {
                e.printStackTrace();
                }
            }

    }



    public static void close(ResultSet rs){
        // 关闭记录集
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }



    public static void freeConn(Connection conn){
        // 关闭链接对象
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
